Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always adding :debug_info on erlc_options #9348

Merged
merged 6 commits into from
Sep 22, 2019

Conversation

kelvinst
Copy link
Contributor

That way, if someone sets erlc_options to [warnings_as_errors: true], :debug_info would still be on the options. To configure it to not save debug info, one should only add debug_info: false to erlc_options

Closes #9184

That way, if someone sets erlc_options to `[warnings_as_errors: true]`,
`:debug_info` would still be on the options. To configure it to not
save debug info, one should only add `debug_info: false` to erlc_options
@kelvinst
Copy link
Contributor Author

I also fixed a doc that was pointing to the wrong default value for :debug_info option on Code.put_compiler_option

@kelvinst
Copy link
Contributor Author

I'm checking how to add tests for this now.

Also, there should be a changelog notice or something like that, since the change breaks compatibility. e.g. if anyone was just dismissing :debug_info on :erlc_options to disable it, that would not work anymore, they would have to change their options to debug_info: false

@kelvinst
Copy link
Contributor Author

I'm checking how to add tests for this now.

So as it is done now, I'm not sure there is any good way of testing it, since it is an inner logic inside Mix.Tasks.Compile.Erlang.do_run. Should I extract the erlc_options build to a public function and unit test it? Maybe we can extract it to Mix.Compilers.Erlang.erlc_options and even document it better there. WDYT?

@josevalim
Copy link
Member

@kelvinst
Copy link
Contributor Author

Yeah, I saw that, but what I couldn't figure out yet is how to check if the :debug_info option was actually applied to compilation.

@michalmuskala
Copy link
Member

michalmuskala commented Sep 14, 2019

@kelvinst it should be possible to check the generated files with :beam_lib.chunks(path, [:debug_info])

@kelvinst
Copy link
Contributor Author

Cool! Thanks @michalmuskala! Really helpful tip (I suppose you mean :beam_lib.chunks, right?)

@kelvinst
Copy link
Contributor Author

PS.: I just realized that I added the default options to the wrong place I guess, that way it will apply it only for the mix compile.erlang task, not when using mix compile. Will fix later.

@kelvinst
Copy link
Contributor Author

Actually, nevermind, just realized mix compile does call mix compile.erlang 🤦‍♂ I'm investigating why @hauleth's example app still don't work with my solution.

@kelvinst
Copy link
Contributor Author

Right, so the problem was that I was just running ../elixir/bin/mix do compile, dialyzer from inside @hauleth's project, and that was not using ../elixir/bin/mix to run the subtasks I suppose. Did test setting PATH=../elixir/bin:$PATH mix do compile, dialyzer and it did work that way, so that really worked.

{:ok, {module, [debug_info: {:debug_info_v1, backend, data}]}} =
:beam_lib.chunks(binary, [:debug_info])

assert backend.debug_info(:elixir_v1, module, data, []) != {:error, :missing}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should assert with :erlang_v1 - after all it's compiling erlang modules, so it's kind of expected it won't be able to return elixir debug info.

Suggested change
assert backend.debug_info(:elixir_v1, module, data, []) != {:error, :missing}
assert backend.debug_info(:erlang_v1, module, data, []) != {:error, :missing}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't even assert this. Asserting it returns a debug info chunk is probably good enough!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean something like this?

{:ok, {_, [debug_info: {:debug_info_v1, _, {info, _}}]}} = :beam_lib.chunks(binary, [:debug_info])
assert info != :none

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked and the only difference is that it returns :none for that part when debug info is disabled, instead of the list of attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have started with that actually, just changed to use backend.debug_info because I was afraid that maybe the format could change in the future and then the test could fail. Very unlikely, but who knows 🤷‍♂

@josevalim
Copy link
Member

josevalim commented Sep 15, 2019 via email

erlc_options: [:debug_info, {:i, 'path/to/include'}]
The following options are always added to `:erlc_options` when running the compiler:

[:debug_info, :return, :report, outdir: compile_path, i: include_path]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return and report are implementation details. If the user changes them, then the compiler will fail. I would remove this section (or talk about only debug_info).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!! I will comment only about debug_info.

@@ -729,7 +729,7 @@ defmodule Mix.Project do
elixirc_paths: ["lib"],
erlc_paths: ["src"],
erlc_include_path: "include",
erlc_options: [:debug_info],
erlc_options: [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be empty since we already add it everytime when compiling erlang.

erlc_options: [:debug_info, {:i, 'path/to/include'}]
The following options are always added to `:erlc_options` when running the compiler:

[:debug_info, :return, :report, outdir: compile_path, i: include_path]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!! I will comment only about debug_info.

@fertapric fertapric merged commit 87d5255 into elixir-lang:master Sep 22, 2019
@fertapric
Copy link
Member

Thanks @kelvinst! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

erlc_options should behave more like elixirc_options
5 participants